package someTestExcemple.thread.communication;

import java.util.concurrent.BlockingQueue;

public class Consumer extends Thread {
    private BlockingQueue<String> blockingQueue;

    public Consumer(BlockingQueue<String> blockingQueue) {
        this.blockingQueue = blockingQueue;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 5; i++) {
                long start = System.currentTimeMillis();
                System.out.println("获取队首元素:" + this.blockingQueue.take());
                long end = System.currentTimeMillis();
                System.out.println("阻塞时长:" + (end - start));
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
